package cocoaas3.Titanium.UI{
	
	import jp.progression.casts.*;
	import jp.progression.commands.display.*;
	import jp.progression.commands.lists.*;
	import jp.progression.commands.managers.*;
	import jp.progression.commands.media.*;
	import jp.progression.commands.net.*;
	import jp.progression.commands.tweens.*;
	import jp.progression.commands.*;
	import jp.progression.data.*;
	import jp.progression.events.*;
	import jp.progression.loader.*;
	import jp.progression.*;
	import jp.nium.core.debug.Logger;
	import caurina.transitions.Tweener;

	import flash.display.*;
	import flash.net.*;
	import flash.geom.*;
	import flash.events.*;

	public class AlertDialog extends Sprite{

		[Embed(source="../../assets.swf", symbol='AlertDialog_design')]
		private var AlertDialog_design:Class;


		private var design;
		private var self:AlertDialog;

		public var message:String = "";
		private var main_mc:MovieClip;


		public function AlertDialog(){
			design = new AlertDialog_design();
			main_mc = design.container_mc.main_mc;
			main_mc.message_txt.autoSize = "center";

			main_mc.ok_btn.addEventListener( MouseEvent.CLICK, _onOK );
		}

		public function show():void{
			main_mc.message_txt.text = message;
			adjustSize();
			main_mc.y = 0 - main_mc.height/2;
			main_mc.cacheAsBitmapMatrix = new Matrix();
			main_mc.cacheAsBitmap = true;


			design.bg_mc.alpha = 0;
			design.container_mc.alpha = 0
			design.container_mc.scaleX = design.container_mc.scaleY = 0.9;
			CastDocument.stage.addChild( design );
			Tweener.addTween( design.bg_mc, {alpha:1, time:0.33} );
			Tweener.addTween( design.container_mc, {alpha:1, scaleX:1, scaleY:1, time:0.33} );
		}

		public function hide():void{
			var slist = new SerialList();
			slist.addCommand(
				[
					new DoTweener( design.bg_mc, {alpha:0, time:0.33} ),
					new DoTweener( design.container_mc, {alpha:0, scaleX:0.9, scaleY:0.9, time:0.33} ),
				],
				function(){
					CastDocument.stage.removeChild( design );
				},
			null);
			slist.execute();
		}

		private function _onOK(e):void{
			hide();
		}


		private function adjustSize(){
			// ボタン一個の場合
			main_mc.bg_mc.height = main_mc.message_txt.y*2 + main_mc.message_txt.height + main_mc.ok_btn.height + 16;
			main_mc.ok_btn.y = main_mc.bg_mc.height - main_mc.ok_btn.height - 16;
		}


	}
}



